package cn.chencq.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.chencq.mq.ConsumerHandler;
import cn.chencq.mq.MQUtil;
import cn.chencq.mq.MqConsumerTemplate;

public class ProcessMsgHelper implements Runnable
{
	private static final Logger LOGGER = LoggerFactory.getLogger(ProcessMsgHelper.class);
	
	private String cluster;
	
	private  ConsumerHandler handler;
	
	private String work;
	
	private String queue;

	public ProcessMsgHelper(String cluster, ConsumerHandler handler,
			String work, String queue)
	{
		super();
		this.cluster = cluster;
		this.handler = handler;
		this.work = work;
		this.queue = queue;
	}

	@Override
	public void run()
	{
		try
		{
			MQUtil.queueDeclare(cluster, queue);
			
			MqConsumerTemplate mqConsumerTemplate = new MqConsumerTemplate(
					false,
					queue, 
					cluster,
					handler);
			
			LOGGER.info("Work-Consumer:{} 启动", work);
			
			mqConsumerTemplate.reciveMsg();
			
		} catch (Exception e)
		{
			LOGGER.error("启动消费者线程异常", e);
		}
		
	}
	
}
